package com.sixth.controller;

import com.fasterxml.jackson.databind.ser.Serializers;
import com.sixth.bean.MarketUser;
import com.sixth.bean.bo.AdminUserListBo;
import com.sixth.bean.common.BasePageInfo;
import com.sixth.bean.common.BasePageInfoVo;
import com.sixth.bean.common.BaseRespVo;
import com.sixth.constant.Constant;
import com.sixth.service.AdminUserService;
import org.apache.shiro.authz.annotation.Logical;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @ClassName AdminUserController
 * @Description TODO
 * @Author XiaoWJ
 * @Date 2022/9/6 22:46
 **/

@RestController
@RequestMapping("admin/user")
public class AdminUserController {

    @Autowired
    AdminUserService adminUserService;


    /**
     * 查询用户的全部信息
     *
     * @Param AdminUserListBo, username, mobile
     * @Return BaseRespVo<BasePageInfoVo>
     * @author XiaoWJ
     * @date 2022/9/7 14:25
     */

    @RequiresPermissions(value = {"admin:user:list"},logical = Logical.OR)
    @RequestMapping("list")
    public BaseRespVo<Object> list(BasePageInfo basePageInfo, String username, String mobile) {

        Object basePageInfoVo = adminUserService.list(basePageInfo, username, mobile);

        return BaseRespVo.ok(basePageInfoVo);
    }

    /**
     * 根据用户id查询用户详细信息
     * @Param  id
     * @Return BaseRespVo<BasePageInfoVo>
     * @author XiaoWJ
     * @date   2022/9/7 14:52
     */

    @RequiresPermissions(value = {"admin:user:detail"},logical = Logical.OR)
    @RequestMapping("detail")
    public BaseRespVo<MarketUser> detail(Integer id){

        MarketUser marketUser = adminUserService.detail(id);

        return BaseRespVo.ok(marketUser);
    }

    /**
     * 更新会员用户信息
     * @Param  MarketUser marketUser
     * @Return
     * @author XiaoWJ
     * @date   2022/9/7 15:21
     */

    @RequiresPermissions(value = {"admin:user:update"},logical = Logical.OR)
    @RequestMapping("update")
    public BaseRespVo<Integer> update(@RequestBody MarketUser marketUser){
        int code = adminUserService.update(marketUser);

        if(code == Constant.NON) {
            return BaseRespVo.invalidData();
        }
        return BaseRespVo.ok(1);
    }

}
